import database.SearchSF;
import database.testtime;
import fingerprint.FingerPrint;
import match.Score;
import match.SongMatcher;
import readfile.GetDoubleArray;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by QianLong on 2016/11/20.
 */

public class Main {
    public static void main(String[] args) {

        testtime t = new testtime();
        t.getnow();

        long currentMillis = System.currentTimeMillis();
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入音频文件地址：");
        String filename = scan.nextLine();
        getSong(filename);
        System.out.println("用时"+String.valueOf(System.currentTimeMillis()-currentMillis)+"ms");

    }

    private static void getSong(String fileName) {
        SearchSF searchSF = new SearchSF();
        double[] timeDomain = GetDoubleArray.GetDoubles(fileName);
        FingerPrint print = new FingerPrint();
        print.generate(timeDomain);
        SongMatcher matcher = new SongMatcher(print.combineHash());
        ArrayList<Score> scores = matcher.selectTarget();
        for (int i = 0; i < (scores.size() < 5?scores.size():5); i++) {
            int score  = scores.get(i).score;
            System.out.println("排第"+String.valueOf(i+1)+"的歌曲是《"+searchSF.SerachSong(scores.get(i).id).replace(".wav","")+"》，分数是"+score);
        }
    }

}
